//
//  VisitorLoginView.swift
//  JJWeibo
//
//  Created by JJ on 15/9/1.
//  Copyright © 2015年 JJ. All rights reserved.
//

import UIKit

//protocol VisitorLoginViewDelegate:NSObjectProtocol{
//    
//    func VisitorLoginViewWillLogin()
//    func VisitorLoginViewWillRegist()
//}

class VisitorLoginView: UIView{
    
//  @objc private func VisitorLoginViewWillLogin(){
//       delegate?.VisitorLoginViewWillLogin()
//    }
//    
//  @objc private func VisitorLoginViewWillRegist(){
//       delegate?.VisitorLoginViewWillRegist()
//    }
    
//   weak var delegate:VisitorLoginViewDelegate?
    
    //MARK: - 设置各个页面的未注册页面
    func setUpInfo(imageName:String?,message:String){
        
        messageLable.text=message
        
        if let imgName=imageName{
            iconView.image=UIImage(named: imgName)
            homeIconView.hidden=true
            sendSubviewToBack(maskIconView)
        }else
        {
            setAnimation()
        }
    
    }
    
    private func setAnimation(){
        
        let ani=CABasicAnimation(keyPath: "transform.rotation")
        
        ani.toValue=2 * M_PI
        ani.duration=5
        ani.repeatCount=MAXFLOAT
        ani.removedOnCompletion=false
        iconView.layer.addAnimation(ani, forKey: nil)
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUI()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setUI()
    }

    // MARK: - 设置UI
    private func setUI(){
    
        addSubview(iconView)
        addSubview(maskIconView)
        addSubview(homeIconView)
        addSubview(messageLable)
        addSubview(registButton)
        addSubview(loginButton)
        
        //旋转图片的布局
        iconView.translatesAutoresizingMaskIntoConstraints=false
        addConstraint(NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: -60))
        
        //小房子的布局
        homeIconView.translatesAutoresizingMaskIntoConstraints=false
        addConstraint(NSLayoutConstraint(item: homeIconView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item: homeIconView, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0))
        
        //消息文本的布局
        messageLable.translatesAutoresizingMaskIntoConstraints=false
        addConstraint(NSLayoutConstraint(item: messageLable, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item: messageLable, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 16))
        addConstraint(NSLayoutConstraint(item: messageLable, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 244))
        
        //注册按钮的布局
        registButton.translatesAutoresizingMaskIntoConstraints=false
        addConstraint(NSLayoutConstraint(item: registButton, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: messageLable, attribute: NSLayoutAttribute.Left, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item:registButton , attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: messageLable, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 16))
        addConstraint(NSLayoutConstraint(item: registButton, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 100))
        addConstraint(NSLayoutConstraint(item: registButton, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 35))
        
        //登陆按钮的布局
        loginButton.translatesAutoresizingMaskIntoConstraints=false
        addConstraint(NSLayoutConstraint(item: loginButton, attribute: NSLayoutAttribute.Right, relatedBy: NSLayoutRelation.Equal, toItem: messageLable, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item: loginButton, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: messageLable, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 16))
        addConstraint(NSLayoutConstraint(item: loginButton, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 100))
        addConstraint(NSLayoutConstraint(item: loginButton, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.Height, multiplier: 1, constant: 35))
        
        //遮罩层的布局-- VFL可视化布局语言
        maskIconView.translatesAutoresizingMaskIntoConstraints=false
        let cons=NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[v]-0-|", options: [], metrics: nil, views: ["v":maskIconView])
        addConstraints(cons)
        addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[v]-(-35)-[regbutton]", options: [], metrics: nil, views: ["v":maskIconView,"regbutton":registButton]))
        
        backgroundColor=UIColor(white: 237.0/255.0, alpha: 1.0)
        
    }

    // MARK: - 懒加载控件
    private lazy var iconView:UIImageView=UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    
    private lazy var homeIconView:UIImageView=UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    
    private lazy var messageLable:UILabel={
        
        let lable=UILabel()
        lable.textColor=UIColor.darkGrayColor()
        lable.textAlignment=NSTextAlignment.Center
        lable.text="关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜"
        lable.numberOfLines=0
        lable.font=UIFont.systemFontOfSize(14)
        
        return lable
    
    }()
    
     lazy var registButton:UIButton={
        
        let btn=UIButton()
        
        btn.setTitle("注册", forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
//        btn.addTarget(self, action: "VisitorLoginViewWillRegist", forControlEvents: UIControlEvents.TouchUpInside)
        
        return btn
    }()
    
     lazy var loginButton:UIButton={
        
        let btn=UIButton()
        
        btn.setTitle("登陆", forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
//        btn.addTarget(self, action: "VisitorLoginViewWillLogin", forControlEvents: UIControlEvents.TouchUpInside)
        return btn
    }()
    
    private lazy var maskIconView:UIImageView=UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
    
    
    
    
}
